﻿/*
 * Log.h
 *
 */
#ifndef __GDK_LOG_H__
#define __GDK_LOG_H__

#include <gdk/core/Types.h>
#include <stdlib.h>



namespace gdk
{


	class GDK_CORE_EXPORT LogListener
	{
	public:
		virtual const Char* getname(void) const = 0;
		virtual void setparam(const Char *param) = 0;
		virtual void message(pid_t tid, class Time const &time, const Char *msg) = 0;
		virtual void warning(pid_t tid, class Time const &time, const Char *msg) = 0;
		virtual void error(pid_t tid, class Time const &time, const Char *msg) = 0;
		virtual void debug(pid_t tid, class Time const &time, const Char *msg) = 0;
	};


	class GDK_CORE_EXPORT Log
	{
	public:
		static bool start(void);
		static void stop(void);

		static void addListener(LogListener* listener);
		static void removeListener(LogListener* listener);
		static LogListener* getLogListener(const Char* name);

		/*
		 * LogFile@path=c:/log/
		 */
		static void setparam(const Char *param);
		static void message(const Char *fmt, ...) __PRINTF_FORMAT(1, 2);
		static void warning(const Char *fmt, ...) __PRINTF_FORMAT(1, 2);
		static void error(const Char *fmt, ...) __PRINTF_FORMAT(1, 2);
		static void debug(const Char *fmt, ...) __PRINTF_FORMAT(1, 2);
	};


#define IMPLEMENT_LOG_LISTENER(Class) \
	static Class g_logListener_##Class;\
	static void removeLogListener_##Class(void)\
	{\
		gdk::Log::removeListener(&g_logListener_##Class);\
	}\
	static bool addLogListener_##Class(void)\
	{\
		gdk::Log::addListener(&g_logListener_##Class);\
		::atexit(removeLogListener_##Class);\
		return true;\
	}\
	const bool g_logListener_##Class##_Flag = addLogListener_##Class();

#define DECLARE_LOG_LISTENER(Class) \
	extern const bool g_logListener_##Class##_Flag;\
	static bool const g_##Class##_flag_ = (gdk::nothing(&g_##Class##_flag_), g_logListener_##Class##_Flag);\
	/*DECLARE_FUTILITY_VARIABLE(static const bool, g_logListener_##Class##_Flag);*/




}//namespace gdk






#endif /*__GDK_LOG_H__*/
